package com.wh.hotel.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.base.Preconditions;
import com.wh.common.annotation.ResultLog;
import com.wh.common.enums.MethodTypeEnum;
import com.wh.common.vo.Result;
import com.wh.hotel.model.HotelBookRule;
import com.wh.hotel.response.HotelBookRuleResponse;
import com.wh.hotel.service.HotelBookRuleService;
import com.wh.hotel.vo.HotelBookRuleVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author wenhao
 */
@RequestMapping("/hotel/book/rule")
@RestController
@Slf4j
public class HotelBookRuleController {

    @Resource
    private HotelBookRuleService hotelBookRuleService;

    /**
     * 新增或修改预订规则
     *
     * @param hotelBookRuleVo
     * @return
     */
    @PostMapping("/save")
    @ResultLog(name = "HotelBookRuleController.saveBookRule", methodType = MethodTypeEnum.HTTP_UP)
    public Result<HotelBookRule> saveBookRule(@RequestBody HotelBookRuleVo hotelBookRuleVo) {
        Preconditions.checkArgument(CollectionUtils.isNotEmpty(hotelBookRuleVo.getPayWayRuleVoList()), "支付方式至少选一个");
        return Result.successResponse(hotelBookRuleService.saveBookRule(hotelBookRuleVo));
    }

    /**
     * 查询规则列表
     *
     * @param hotelBookRuleVo
     * @return
     */
    @PostMapping("/list")
    @ResultLog(name = "HotelBookRuleController.list", methodType = MethodTypeEnum.HTTP_UP)
    public Result<IPage<HotelBookRuleResponse> > list(@RequestBody HotelBookRuleVo hotelBookRuleVo) {
        return Result.successResponse(hotelBookRuleService.queryPageList(hotelBookRuleVo));
    }

    /**
     * 查询规则详情
     *
     * @param hotelBookRuleVo
     * @return
     */
    @PostMapping("/detail")
    @ResultLog(name = "HotelBookRuleController.detail", methodType = MethodTypeEnum.HTTP_UP)
    public Result<HotelBookRuleResponse> detail(@RequestBody HotelBookRuleVo hotelBookRuleVo) {
        Preconditions.checkNotNull(hotelBookRuleVo.getId(), "预订规则ID不能空");
        return Result.successResponse(hotelBookRuleService.detail(hotelBookRuleVo));
    }
}
